#! /usr/bin/env python
# -*- coding:utf-8 -*-
# author:无涯

#! /usr/bin/env python
# -*- coding:utf-8 -*-
# author:无涯

import  time
from  locust import  HttpUser,task,between
import  json

class QuickStartUser(HttpUser):
   wait_time = between(1,2.5)

   def writeToken(self,content):
      json.dump(content,open('token','w'))

   def getToken(self):
      return json.load(open('token'))

   @task
   def login(self):
      r=self.client.post(
         url='/login/auth/',
         json={"username":"13484545195","password":"asd888"})
      self.writeToken(content=r.json()['token'])
      assert r.status_code==200

   @task
   def index(self):
      r=self.client.get(
         url='/interface/index',
         headers={'Authorization':'JWT {token}'.format(token=self.getToken())})
      assert r.status_code==200

   @task
   def product(self):
      r=self.client.get(
         url='/interface/product/',
         headers={'Authorization':'JWT {token}'.format(token=self.getToken())})
      assert r.status_code==200